extern uniform float4x4 gWorld;
extern uniform float4x4 gWorldInvTran;
extern uniform float3	gEyePos;
extern uniform float4x4	gVP;
extern uniform float4	gColor;

struct VS_INPUT
{
    float3 posL			: POSITION0;
    float3 normalL		: NORMAL0;
    float3 faceNormal1	: NORMAL1; 
    float3 faceNormal2	: NORMAL2;
};

struct VS_OUTPUT
{
    float4 posH		: POSITION0;
    float4 diffuse	: COLOR0;
};

VS_OUTPUT VS(VS_INPUT input)
{
	VS_OUTPUT output = (VS_OUTPUT)0;

	float3 posW = mul(float4(input.posL, 1.0f), gWorld).xyz;
	float3 normalW = mul(float4(input.normalL, 0.0f), gWorldInvTran).xyz;
	float3 faceNormal1W = mul(float4(input.faceNormal1, 0.0f), gWorldInvTran).xyz;
	float3 faceNormal2W = mul(float4(input.faceNormal2, 0.0f), gWorldInvTran).xyz;

	float3 toEyeVec = posW - gEyePos;

	if(dot(toEyeVec, faceNormal1W) * dot(toEyeVec, faceNormal2W) < 0.0f)
	{
		posW += 0.1f * normalW;
	}

	output.posH = mul(float4(posW, 1.0f), gVP);
	output.diffuse = gColor;

	return output;
}

float4 PS(float4 diffuse : COLOR0) : COLOR0
{
	return diffuse;
}

technique OutlineTech
{
	pass P0
	{
        vertexShader = compile vs_2_0 VS();
        pixelShader  = compile ps_2_0 PS();
	}
}